package servlet;

import java.io.IOException;
import java.util.Properties;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import modelo.Cliente;


/**
 * Servlet implementation class ServletCadastroCliente
 */
@WebServlet("/cadastro.do")
public class ServletCadastroCliente extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private Properties mapa;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ServletCadastroCliente() {
        super();
        // TODO Auto-generated constructor stub
    }
    
    public void init() throws ServletException{
    	try{
    		this.mapa = new Properties();
    		String caminho = this.getServletContext().getInitParameter("caminho");
    		this.mapa.load(this.getServletContext().getResourceAsStream(caminho));
    		
    }  catch (IOException e)
	{
		System.out.println("Caminho inexistente");
		e.printStackTrace();
	}
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    		
		try{	
			Cliente c = new Cliente();
			String nome = request.getParameter("edtNome");
			String pass = request.getParameter("edtSenha");
			
			if(c.cadastrarClientes(nome, pass)){
				response.sendRedirect("index.html");
			}
			else
				response.sendRedirect("erro.html");
		} 
		
		catch (IOException e){
			e.printStackTrace();
		}

}
    

}